﻿#include "GUILoadPickSubSysDialog.h"
#include "ui_GUILoadPickSubSysDialog.h"

#include "FITK_Kernel/FITKCore/FITKActionOperator.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"

// Pick
#include "PickDataProvider/GUIPickInfo.h"
#include "PickDataProvider/PickedDataProvider.h"

#include <QButtonGroup>
#include <QRegExpValidator>
#include <QTabBar>

namespace GUI {

    GUILoadPickSubSysDialog::GUILoadPickSubSysDialog(Core::FITKActionOperator* oper, QWidget* parent /*= nullptr*/) :
        GUIDialogBase(parent),
        _oper(oper),
        _ui(new Ui::GUILoadPickSubSysDialog)
    {
        _ui->setupUi(this);
        // 设置对话框关闭时自动删除
        setAttribute(Qt::WA_DeleteOnClose);
        //去掉问号
        Qt::WindowFlags flags = windowFlags();
        flags &= ~Qt::WindowContextHelpButtonHint;
        setWindowFlags(flags);
        //初始化数据
        this->init();
    }

    GUILoadPickSubSysDialog::~GUILoadPickSubSysDialog()
    {
        if (_ui) {
            delete _ui;
            _ui = nullptr;
        }
    }

    void GUILoadPickSubSysDialog::on_comboBox_PickModel_currentIndexChanged(int index)
    {
        //获取拾取类型
        GUI::GUIPickInfo::PickObjType pickType = GUI::GUIPickInfo::PickObjType(_ui->comboBox_PickModel->currentData().toInt());
        GUI::GUIPickInfoStru pickInfo = GUI::GUIPickInfo::GetPickInfo();
        pickInfo._pickMethod = GUI::GUIPickInfo::PickMethod::PMSingle;
        pickInfo._pickObjType = pickType;
        //设置拾取类型
        GUI::GUIPickInfo::SetPickInfo(pickInfo);
    }

    void GUILoadPickSubSysDialog::on_pushButton_Cancel_clicked()
    {
        this->reject();
    }

    void GUILoadPickSubSysDialog::on_pushButton_OK_clicked()
    {
        this->accept();
    }

    void GUILoadPickSubSysDialog::reject()
    {
        //清除拾取模式和高亮
        GUI::GUIPickInfo::ClearPickInfo();
        this->QDialog::reject();
    }

    void GUILoadPickSubSysDialog::init()
    {
        if (!_oper) return;
        //获取需要创建的类型
        QString loadType;
        if (!_oper->argValue("LoadType", loadType)) return;
        //初始化下拉框
        if (loadType == "Power")
        {
            _ui->comboBox_PickModel->addItem(tr("SEA Shell"), GUI::GUIPickInfo::PickObjType::POBJSEAShell);
            _ui->comboBox_PickModel->addItem(tr("SEA Beam"), GUI::GUIPickInfo::PickObjType::POBJSEABeam);
            _ui->comboBox_PickModel->addItem(tr("SEA Acoustic Cavity"), GUI::GUIPickInfo::PickObjType::POBJSEACavity);
            _ui->comboBox_PickModel->addItem(tr("FE SubSystem"), GUI::GUIPickInfo::PickObjType::POBJFEStructure);
        }
        else if (loadType == "PointForce")
        {
            _ui->comboBox_PickModel->addItem(tr("SEA Shell"), GUI::GUIPickInfo::PickObjType::POBJSEAShell);
            _ui->comboBox_PickModel->addItem(tr("SEA Beam"), GUI::GUIPickInfo::PickObjType::POBJSEABeam);
            _ui->comboBox_PickModel->addItem(tr("FE SubSystem"), GUI::GUIPickInfo::PickObjType::POBJFEStructure);
        }
        else if (loadType == "Constraint")
        {
            _ui->comboBox_PickModel->addItem(tr("SEA Shell"), GUI::GUIPickInfo::PickObjType::POBJSEAShell);
            _ui->comboBox_PickModel->addItem(tr("SEA Beam"), GUI::GUIPickInfo::PickObjType::POBJSEABeam);
            _ui->comboBox_PickModel->addItem(tr("SEA Acoustic Cavity"), GUI::GUIPickInfo::PickObjType::POBJSEACavity);
            //_ui->comboBox_PickModel->addItem(tr("FE SubSystem"), GUI::GUIPickInfo::PickObjType::POBFEStructure);
        }
        else if (loadType == "HVACNoise")
        {
            _ui->comboBox_PickModel->addItem(tr("SEA Acoustic Cavity"), GUI::GUIPickInfo::PickObjType::POBJSEACavity);
        }
        else if (loadType == "Monopole")
        {
            _ui->comboBox_PickModel->addItem(tr("SEA Acoustic Cavity"), GUI::GUIPickInfo::PickObjType::POBJSEACavity);
        }
        // this->on_comboBox_PickModel_currentIndexChanged(_ui->comboBox_PickModel->currentIndex());
    }
}
